//
//  CalenderViewController.m
//  New
//
//  Created by dlios on 15-7-16.
//  Copyright (c) 2015年 yangTao. All rights reserved.
//

#import "CalenderViewController.h"

@interface CalenderViewController ()

@end

@implementation CalenderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    BaseLabel *title =[[BaseLabel alloc]initWithFrame:CGRectMake(WIDTH/2 - 60, 5, 120, 40)];
    title.backgroundColor = [UIColor clearColor];
    self.navigationItem.titleView =title;
    title.text = @"日历";
    title.textAlignment = NSTextAlignmentCenter;
    title.font = [UIFont systemFontOfSize:20];
    
    BaseButton *dateButton = [[BaseButton alloc]initWithFrame:CGRectMake(WIDTH - 100, 20, 90, 40)];
    dateButton.backgroundColor = [UIColor clearColor];
    [self.navigationController.view addSubview:dateButton];
    [dateButton addTarget:self action:@selector(dateAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.label1 = [[BaseLabel alloc]initWithFrame:CGRectMake(0, 0, dateButton.frame.size.width, 20)];
    self.label1.backgroundColor = [UIColor clearColor];
    [dateButton addSubview:self.label1];
    
    self.label1.textAlignment = NSTextAlignmentCenter;
    
    self.label2 = [[BaseLabel alloc]initWithFrame:CGRectMake(0, 20, dateButton.frame.size.width, 20)];
    self.label2.backgroundColor = [UIColor clearColor];
    [dateButton addSubview:self.label2];
    self.label2.textAlignment = NSTextAlignmentCenter;
    
    self.dateVC = [[DateViewController alloc]init];
    [self addChildViewController:self.dateVC];
    [self.view addSubview:self.dateVC.view];
    self.dateVC.myDalegate = self;
    
    
    self.calenderVC = [[calenderDetailViewController alloc]init];
    [self addChildViewController:self.calenderVC];
    [self.view addSubview:self.calenderVC.view];
    
    
    self.isSelect = NO;
    
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy"];
    self.label1.text =[NSString stringWithFormat:@"%@",
                       [formatter stringFromDate:date]];
    
    [formatter setDateFormat:@"MM"];
    NSString *string1 =[NSString stringWithFormat:@"%ld",[[formatter stringFromDate:date]integerValue]];
     [formatter setDateFormat:@"dd"];
    NSString *string2 =[NSString stringWithFormat:@"%@",[formatter stringFromDate:date]];
    NSString *str = [NSString stringWithFormat:@"%@月  %@日",string1,string2];
    

    
    
    self.label2.text = str;
    // Do any additional setup after loading the view.
}
-(void)dateAction{
    if (self.isSelect == NO) {
        
        [self.view bringSubviewToFront:self.dateVC.view];

        self.isSelect = YES;
    }else{
    
        [self.view bringSubviewToFront:self.calenderVC.view];
        
        
        
        self.isSelect = NO;
    
    }


}

-(void)bringButtonyear:(NSString *)year AndMouth:(NSString *)mouth andDate:(NSString *)date{
    [self.view bringSubviewToFront:self.calenderVC.view];
    self.isSelect = NO;
    
    if ((year == nil) && (mouth == nil) && (date == nil)) {
        NSDate *date = [NSDate date];
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy"];
        NSString *str1 =[NSString stringWithFormat:@"%@",
                        [formatter stringFromDate:date]];
        self.label1.text =str1;
        
        [formatter setDateFormat:@"MM"];
        NSString *string1 =[NSString stringWithFormat:@"%02ld",[[formatter stringFromDate:date]integerValue]];
        [formatter setDateFormat:@"dd"];
        NSString *string2 =[NSString stringWithFormat:@"%02ld",[[formatter stringFromDate:date]integerValue]];
      NSString *str2 =[NSString stringWithFormat:@"%02ld",[[formatter stringFromDate:date]integerValue]-1];
        NSString *str = [NSString stringWithFormat:@"%@月  %@日",string1,string2];
         self.label2.text = str;
        
        NSString *string3 = [NSString stringWithFormat:@"%@-%@-%@",str1,string1,string2];
        NSString *string4 =[NSString stringWithFormat:@"%@-%@-%@",str1,string1,str2];
        
        [self.calenderVC bringDate:string4 andDate1:string3];
        
    }else if ((year == nil) && (mouth != nil) && (date != nil)){
        NSDate *date1 = [NSDate date];
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy"];
        NSString *str2 =[NSString stringWithFormat:@"%@",
                         [formatter stringFromDate:date1]];
        self.label1.text = str2;
        
        
        self.label2.text = [NSString stringWithFormat:@"%@月  %@日",mouth,date];
        
        
        NSInteger num = [mouth integerValue];
        NSInteger num1 = [date integerValue];
        
        NSString *str = [NSString stringWithFormat:@"%@-%02ld-%02ld",str2,num,num1];
        NSString *str1 = [NSString stringWithFormat:@"%@-%02ld-%02ld",str2,num,num1-1];

        
        [self.calenderVC bringDate:str1 andDate1:str];
        
    }else if ((year == nil) && (mouth == nil) && (date != nil)){
        NSDate *date1 = [NSDate date];
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy"];
        NSString *str2 =[NSString stringWithFormat:@"%@",
                         [formatter stringFromDate:date1]];
        
        [formatter setDateFormat:@"MM"];
        
        NSString *string1 =[NSString stringWithFormat:@"%02ld",[[formatter stringFromDate:date1] integerValue]];
       
        
        self.label1.text = str2;
        
        self.label2.text = [NSString stringWithFormat:@"%@月  %@日",string1,date];

            NSInteger num1 = [date integerValue];
        
        NSString *str = [NSString stringWithFormat:@"%@-%@-%02ld",str2,string1,num1];
        NSString *str1 = [NSString stringWithFormat:@"%@-%@-%02ld",str2,string1,num1-1];
        
        [self.calenderVC bringDate:str1 andDate1:str];

        
    }

    
    else{
    
    self.label1.text = year;
    NSString *string = [NSString stringWithFormat:@"%@月  %@日",mouth,date];
    self.label2.text = string;
        NSInteger num = [mouth integerValue];
        NSInteger num1 = [date integerValue];
        
        NSString *str = [NSString stringWithFormat:@"%@-%02ld-%02ld",year,num,num1];
        NSString *str1 = [NSString stringWithFormat:@"%@-%02ld-%02ld",year,num,num1-1];
        [self.calenderVC bringDate:str1 andDate1:str];

    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
